package com.spark.check

import android.support.annotation.LayoutRes
import android.widget.ImageView
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.spark.check.model.TaskModel
import com.spark.check.widget.ItemTaskContentView
import com.spark.colliery.common.ext.gone
import com.spark.colliery.common.ext.isVisible
import com.spark.common.ext.append

/**
 * TasksAdapter
 */
class TasksAdpater(@LayoutRes layoutRes: Int) : BaseQuickAdapter<TaskModel, BaseViewHolder>(layoutRes) {
    override fun convert(helper: BaseViewHolder?, item: TaskModel?) {
        helper?.apply {
            if (item == null) return
            setText(R.id.tv_score, item.score)
            setText(R.id.tv_name, "${item.chapter}${item.title}")
            setText(R.id.tv_responsble, "责任：${item.responsible}")
            setText(R.id.tv_cooperate, "配合：${item.cooperate.append("、")}")
            setText(R.id.tv_invite, "特邀：${item.invited.append("、")}")
            setText(R.id.tv_content_title, item.name)
            setText(R.id.tv_content_serial, "编号：${item.serialnum}")
            getView<ItemTaskContentView>(R.id.item_task_content).let { it as ItemTaskContentView }.bind(item.content)

            val llTaskContent = getView<LinearLayout>(R.id.ll_task_content)
            llTaskContent.gone(true)
            getView<ImageView>(R.id.iv_expand).setOnClickListener {
                val currState = llTaskContent.isVisible()
                llTaskContent.gone(currState)
            }
        }
    }

}